import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2022-01-05
 * Time:10:59
 */


class Card{
    public String suit;
    public int values;

    @Override
    public String toString() {
//        return "Card{" +
//                "suit='" + suit + '\'' +
//                ", values=" + values +
//                '}';
        return "[" + suit + values+"]";
    }

    public Card(String suit, int values) {
        this.suit = suit;
        this.values = values;
    }
}
public class CardDemo {
    public static String[] suits ={"♠","♥","♣","♦"};
    public static List<Card> buyCards(){
        List<Card> cards = new ArrayList<>();
        for (int i = 1; i <= 13; i++) {
            for (int j = 1; j <= 4; j++) {
                cards.add(new Card(suits[j - 1],i));
            }
        }
        return cards;
    }
public static void shuffle(List<Card> cards){
        int size = cards.size();
    for (int i = size - 1; i > 0; i--) {
        Random random = new Random();
        int ramNum = random.nextInt(i);//[0,i)生成该范围的函数
        swap(cards,i,ramNum);
    }
}

    private static void swap(List<Card> cards, int i, int ramNum) {
        Card card = cards.get(i);
        cards.set(i,cards.get(ramNum));
        cards.set(ramNum,card);
    }

    public static void main(String[] args) {
        List<Card> cards = buyCards();
        System.out.println(cards);
        shuffle(cards);
        System.out.println(cards);
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);

        while (cards.size() > 0){

            for (int j = 0; j < 3; j++) {
                if (cards.size() <= 0){
                    break;
                }
                int i = cards.size() - 1;
                Card card = cards.remove(i);
                hands.get(j).add(card);
            }
        }
        System.out.println(hands.get(0));
        System.out.println(hands.get(1));
        System.out.println(hands.get(2));
    }
}
